package template_jss;

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class SimpleMail
{
       static String  d_email = "jss@andwise.com",
          d_password = "jss9115",
          d_host = "smtp.gmail.com",
          d_port  = "465",            
          m_subject = " [딥체커 - 웹 접근성 검사]가 완료되었습니다.",
          m_text_header = "아래의 링크를 따라가시면 결과를 보실 수 있습니다.\n\n",
          m_text_footer = "\n\n최고의 퀄리티로 서비스하는 디비딥이 되겠습니다.";
//       m_text_header = "<br>아래의 링크를 따라가시면 결과를 보실 수 있습니다.</br><p style='font-size:20pt'>Result : ",
//       m_text_footer = "</p><br>최고의 퀄리티로 서비스하는 디비딥이 되겠습니다.</br>";
//SimpleMail.sendMail(d_email, d_password, d_host, d_port, "true", "true", true, "javax.net.ssl.SSLSocketFactory", "false", to, null, null, m_subject, m_text_header + "http://www.dbdib.com/DibChecker/result/site_result.jsp?_key=A3E91382FC085FA39D41432D7E166D7D" + m_text_footer);
//         sendMail(String userName,String passWord,String host,String port,String starttls,String auth,boolean debug,String socketFactoryClass,String fallback,String[] to,String[] cc,String[] bcc,String subject,String text){
  public synchronized static boolean sendMail(String title, String[] to, String key){
  	boolean debug = false;
      Properties props = new Properties();
      //Properties props=System.getProperties();
	    props.put("mail.smtp.user", d_email);
	    props.put("mail.smtp.host", d_host);
	            if(!"".equals(d_port))
	    props.put("mail.smtp.port", d_port);
	            if(!"".equals("true"))
	    props.put("mail.smtp.starttls.enable","true");
	    props.put("mail.smtp.auth", "true");
	            if(debug){
	            props.put("mail.smtp.debug", "true");
	            }else{
	            props.put("mail.smtp.debug", "false");         
	            }
	            if(!"".equals(d_port))
	    props.put("mail.smtp.socketFactory.port", d_port);
	            if(!"".equals("javax.net.ssl.SSLSocketFactory"))
	    props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
	            if(!"".equals("false"))
	    props.put("mail.smtp.socketFactory.fallback", "false");
	 
	        try
	        {
	                        Session session = Session.getDefaultInstance(props, null);
	            session.setDebug(debug);
	            MimeMessage msg = new MimeMessage(session);
	            msg.setText(m_text_header + key + m_text_footer);
	            msg.setSubject(title + m_subject);
	            msg.setFrom(new InternetAddress("jss@andwise.com"));
	            if(to[0] != null && to[0] != "undefined" && to[0] != ""){
	            	for(int i=0;i<to.length;i++)
	            		msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to[i]));
	            }
	            msg.saveChanges();
	            Transport transport = session.getTransport("smtp");
              transport.connect(d_host, d_email, d_password);
              transport.sendMessage(msg, msg.getAllRecipients());
              transport.close();
              return true;
	    }
	    catch (Exception mex)
	    {
	        mex.printStackTrace();
	                    return false;
	    }
  } 
  public static void main(String[] args)
  {
	  String to[]={"jss@andwise.com"};
SimpleMail.sendMail("aaa", to, "aa");
  }



}